<template>
  <div class="page-content">
    <h3 class="table-title"><i class="iconfont-sys">&#xe74d;</i>更新日志</h3>
    <div class="tips">我们致力于通过解决错误并经常在每个版本中实现新功能来不断改进。</div>
    <div class="tips-title">您可以在下面找到我们最新的更新说明。</div>

    <div class="version-timeline">
      <div v-for="(item, index) in versions" :key="index" class="timeline-entry">
        <!-- 左侧日期 -->
        <div class="timeline-date">
          <div class="day">{{ item.updateTime.slice(0, 10).split('-')[2] }}</div>
          <div class="month">{{ `${item.updateTime.slice(0, 10).split('-')[0]}-${item.updateTime.slice(0,
            10).split('-')[1]}` }}</div>
        </div>

        <!-- 右侧内容区 -->
        <div class="timeline-main">
          <!-- 节点圆点 & 线段 -->
          <div class="timeline-line">
            <div class="dot"></div>
            <div v-if="index < versions.length - 1" class="line"></div>
          </div>

          <!-- 主体内容 -->
          <div class="timeline-content">
            <div class="version-header">
              <div class="version-title">V{{ item.versionNo }}</div>
              <div class="version-sub">小程序版本号：{{ item.wxVersionNo }}</div>
              <div class="version-sub">备注：{{ item.versionContent }}</div>
            </div>
            <div class="content-line"></div>
            <div class="version-box">
              <div class="title">更新内容</div>
              <ul class="list">
                <div v-if="item.addContent">
                  <li v-for="(log, i) in item.addContent.split(',')" :key="i" class="list-item">
                    <el-tag type="primary">新增</el-tag>
                    <span>{{ log }}</span>
                  </li>
                </div>
                <div v-if="item.optimizeContent">
                  <li v-for="(log, i) in item.optimizeContent.split(',')" :key="i" class="list-item">
                    <el-tag type="success">优化</el-tag>
                    <span>{{ log }}</span>
                  </li>
                </div>
                <div v-if="item.updateContent">
                  <li v-for="(log, i) in item.updateContent.split(',')" :key="i" class="list-item">
                    <el-tag type="warning">修复</el-tag>
                    <span>{{ log }}</span>
                  </li>
                </div>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { updateLog } from '@/api/driverSchoolApi'

interface VersionLog {
  updateTime: string
  versionNo: string
  wxVersionNo: string
  versionContent: string
  addContent: string
  updateContent: string
  optimizeContent: string
}

const pageNum = ref(1)
const pageSize = ref(10)
const tableLoading = ref(false)
async function getData() {
  try {
    tableLoading.value = true

    const { code, data } = await updateLog({
      pageNum: pageNum.value,
      pageSize: pageSize.value
    })
    if (code === '00000') {
      versions.value = data.list
    }
  } catch (e) {
  } finally {
    tableLoading.value = false
  }
}

onMounted(() => {
  getData()
})

const versions = ref<VersionLog[]>([])
</script>

<style lang="scss" scoped>
.page-content {
  .version-timeline {
    display: flex;
    flex-direction: column;
    padding-left: 1rem;
    margin-top: 70px;
    width: 100%;
  }

  .tips {
    margin-top: 30px;
    font-size: 14px;
    margin-left: 15px;
  }

  .tips-title {
    margin-top: 10px;
    font-size: 14px;
    margin-left: 15px;
  }

  .timeline-entry {
    display: flex;
    flex-direction: row;
    margin-bottom: 2rem;
    align-items: flex-start;
    width: 100%;
  }

  .timeline-date {
    width: 120px;
    text-align: center;
    margin-right: 10px;

    .day {
      font-size: 20px;
      color: var(--el-color-primary);
      font-weight: bold;
      margin-bottom: 6px;
    }

    .month {
      font-size: 16px;
      color: #999;
    }
  }

  .timeline-main {
    display: flex;
    flex-direction: row;
    position: relative;
    flex: 1;
    width: 100%;
  }

  .timeline-line {
    width: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    margin-right: 12px;

    .dot {
      width: 10px;
      height: 10px;
      background-color: var(--el-color-primary);
      border-radius: 50%;
      border: 2px solid #fff;
      z-index: 2;
    }

    .line {
      flex-grow: 1;
      width: 2px;
      background-color: #e5e7ed;
      margin-top: 0px;
    }
  }

  .timeline-content {
    width: 100%;
    flex: 1;

    .version-header {
      margin-bottom: 8px;

      .version-title {
        font-weight: bold;
        font-size: 16px;
        margin-bottom: 10px;
      }

      .version-sub {
        font-size: 14px;
        color: #ccc;
        margin-bottom: 10px;
      }
    }

    .content-line {
      width: 100%;
      height: 1px;
      background-color: #e5e7ed;
      opacity: 0.5;
      margin: 20px 0;
    }

    .version-box {
      .title {
        font-weight: bold;
        margin-bottom: 20px;
      }

      .list {
        padding-left: 0;
        margin: 0;
        list-style: none;

        .list-item {
          display: flex;
          gap: 6px;
          align-items: center;
          font-size: 14px;
          margin-bottom: 20px;
        }
      }
    }
  }
}
</style>
